///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2011 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_IO_SERIALIZATION_H_
#define _BUOLA_IO_SERIALIZATION_H_

#include <buola/buola.h>

namespace buola { namespace io {

///\addtogroup io
///@{

template<typename tSerializer,typename tType>
void serialize(tSerializer &pS,const std::vector<tType> &pV)
{
    pS << pV.size();
    for(const auto &e : pV)
        pS << e;
}

template<typename tSerializer,typename tType>
void deserialize(tSerializer &pS,std::vector<tType> &pV)
{
    typename std::vector<tType>::size_type lSize;
    pS >> lSize;
    pV.resize(lSize);
    for(int i=0;i<lSize;i++)
        pS >> pV[i];
}

template<typename tSerializer,typename tKey,typename tValue>
void serialize(tSerializer &pS,const std::map<tKey,tValue> &pMap)
{
    pS << pMap.size();
    for(const auto &e : pMap)
        pS << e.first << e.second;
}

template<typename tSerializer,typename tKey,typename tValue>
void deserialize(tSerializer &pS,std::map<tKey,tValue> &pMap)
{
    pMap.clear();
    typename std::map<tKey,tValue>::size_type lSize;
    pS >> lSize;
    for(int i=0;i<lSize;i++)
    {
        tKey lKey;
        tValue lValue;
        pS >> lKey >> lValue;
        pMap.emplace(std::move(lKey),std::move(lValue));
    }
}

///@}

/*namespace io*/ } /*namespace buola*/ }

#endif
